<template>
    <el-dialog title="是否同意退款?" :visible.sync="open" :before-close="close" append-to-body>
        <el-form :model="f">
            <el-form-item label="订单编号" :label-width="formLabelWidth">
                {{ orderCode }}
            </el-form-item>
            <el-form-item label="实付金额" :label-width="formLabelWidth">
                {{goodinfo.orderPrice}}
            </el-form-item>
            <el-form-item label="退款金额" :label-width="formLabelWidth">
                <el-input v-model="f.orderprice" auto-complete="off" style="width:30%" placeholder="小数点后不能大于两位"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="close()">取 消</el-button>
            <el-button type="primary" @click="save()">确 定</el-button>
        </div>
    </el-dialog>
</template>
<script>
import lockr from 'lockr'
export default {
    data(){
        return{
            open:false,
            orderCode:"",
            f:{},
            goodinfo:{}
        }
    },
    computed:{
        getstate(){
            return this.$store.state.ordertuikuanclass;
        },
        getchange(){
            return this.$store.state.ordertuikuan;
        }
    },
    watch:{
        getstate(v){
            this.open=v
        },
        getchange(v){
            if(v){
                this.orderCode=v.orderCode
                this.goodinfo=v
            }
        }
    },
    methods:{
        close(){
            this.f={}
            this.$store.state.ordertuikuan={}
            this.$store.state.ordertuikuanclass=false
        },
        checknumber(n){
            if(n.indexOf('.')!=-1){
                if(n.toString().split(".")[1].length>2){
                    return false
                }else{
                    return true
                }
            }else{
                return true
            }
        },
        save(){
            var _this=this
            // if(this.goodinfo.orderStatus==8){
            //     var pt=new URLSearchParams()
            //     pt.append('orderCode',this.orderCode)
            //     if(!this.f.orderprice){
            //         this.$message.error('请填写退款金额')
            //         return
            //     }
            //     pt.append('price',this.f.orderprice)
            //     pt.append('userName',lockr.get('username'))
            //     axios.get('/refundByOrderId.do',{params:pt}).then(r=>{
            //         if(r.data.code==200){
            //             _this.$message.success('退款成功')
            //             _this.close()
            //         }else{
            //             _this.$message.error(r.data.message)
            //         }
            //     }).catch(e=>{
            //         _this.$message.error(e)
            //     })
            // }else{

                var pp=new URLSearchParams()
                pp.append('orderCode',this.orderCode)
                if(!this.f.orderprice){
                    this.$message.error('请填写退款金额')
                    return
                }
                if(!this.checknumber(this.f.orderprice)){
                    this.$message.error('退款金额小数点后不能多于两位')
                    return
                }
                pp.append('price',this.f.orderprice)
                pp.append('userName',lockr.get('username'))
                axios.get('/refundByOrderPrice.do',{params:pp}).then(r=>{
                    if(r.data.code==200){
                        _this.$message.success('申请退款中')
                        _this.$store.state.ordertuikuandialog=false
                        console.log("申请发起1",_this.$store.state.ordertuikuandialog)
                        _this.close()
                    }else{
                        _this.$message.error(r.data.message)
                    }
                })


            // }
        }
    }
}
</script>
<style scoped>
.el-dialog__header {
    padding: 10px;
    background-color: #20a0ff!important;
}
</style>
